<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="author" content="jack">
    <script type="text/javascript" src="${baseUrlStatic}/js/Bootstrap/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="${baseUrlStatic}/js/Bootstrap/bootstrap.min.js"></script>
	<script type="text/javascript" src="${baseUrlStatic}/js/rate/biz.ajax.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			var auto_rate_switch = "${sellerConfig.auto_rate_switch}";
			var controlValue = initControlStatus(auto_rate_switch);
			var black_list_switch = "${sellerConfig.black_list_switch}";
			if(black_list_switch == "1"){
				$("#blackOpen").attr("checked",'checked');
			}else{
				$("#blackClosed").attr("checked",'checked');
			}
			var trade_rate_condition = "${sellerConfig.trade_rate_condition}";
			var rate_condition_day = "${sellerConfig.rate_condition_day}";
			if(trade_rate_condition == "1"){
				$("#buyerCondition").attr("checked",'checked');
			}else if(trade_rate_condition == "2"){
				$("#allCondition").attr("checked",'checked');
			}else if(trade_rate_condition == "3"){
				$("#fillCondition").attr("checked",'checked');
			}
			var grab_switch = "${sellerConfig.grab_switch}";
			if(grab_switch == "1"){
				$("#grabOpen").attr("checked",'checked');
			}else{
				$("#grabClosed").attr("checked",'checked');
			}
			$("#controlRate").click(function(){
				controlValue = $("#controlRate").val();
				controlSat(controlValue);
			});
			$("#saveConfig").click(function(){
				var data = {};
				data.black_list_switch = $('input:radio[name="black_list_switch"]:checked').val();
				data.trade_rate_condition = $('input:radio[name="trade_rate_condition"]:checked').val();
				data.grab_switch = $('input:radio[name="grab_switch"]:checked').val();
				var url = "/sellerConfig/updateConfig";
				control(url, data, function(result) {
					if(result){
						var objs = eval(result);
						var sellerConfig = objs.sellerConfig;
	 					if(result.status && result.status==1){
	 						alert("更新成功");
	 					} else {
	 						alert("更新失败");
	 					}
					}
				},{message:"test", ui:parent});
			});
		});
		
		
		//控制自动评价开关
		function controlSat(controlValue) {
			var data = {};
			data.controlValue = controlValue;
			var url = "/sellerConfig/control";
			control(url, data, function(result) {
				if(result){
					var objs = eval(result);
					var sellerConfig = objs.sellerConfig;
					auto_rate_switch = sellerConfig.auto_rate_switch;
					initControlStatus(auto_rate_switch);
					tenSecondDisable(auto_rate_switch);
// 					if(result.status && result.status==1){
// 						alert(result.message);
// 					} else {
// 						alert(result.message);
// 					}
				}
			},{message:"test", ui:parent});
		}
		
		function control(url, data, callback, options){
			ajaxPost(url, data, 
				function(result) {
					if (callback) {
		                callback(result);
		            }
                }, null, options);	
		}
		
		function tenSecondDisable(auto_rate_switch){
			$("#controlRate").attr("disabled", 'disabled');
			start(auto_rate_switch);
		}
		function start(auto_rate_switch){
		    document.getElementById("controlStatus").value = 10;
// 		    window.setTimeout("tick()",1000);
		    window.setTimeout(function(){   
		    	tick(auto_rate_switch);   
		    }, 1000);
		    
		}
		function tick(auto_rate_switch){
		    var time = new Number(document.getElementById("controlStatus").value);
		    if(time>0){
		    	$("#controlRate").text("(" + (time - 1) + ")" + "秒后继续操作");
		        document.getElementById("controlStatus").value = time-1;
		        window.setTimeout(function(){   
			    	tick(auto_rate_switch);   
			    }, 1000);
		    }
		    else{
		    	$("#controlRate").removeAttr("disabled");
		    	initControlStatus(auto_rate_switch);
		    }
		}
		
		function initControlStatus(auto_rate_switch){
			var controlValue = true;
			if(auto_rate_switch == true){
		 		$("#controlStatus").removeClass("closedControl");
		 		$("#controlStatus").addClass("openControl");
		 		$("#controlRate").attr("value",false);
		 		controlValue = false;
		 		$("#controlStatus").text("已开启");
		 		$("#controlRate").text("点击关闭服务");
		 		$("#controlRate").removeClass("btn-info");
		 		$("#controlRate").addClass("btn-danger");
		 	}else{
		 		$("#controlStatus").removeClass("openControl");
		 		$("#controlStatus").addClass("closedControl");
		 		$("#controlRate").attr("value",true);
		 		$("#controlStatus").text("已关闭");
		 		$("#controlRate").text("点击开启服务");
		 		$("#controlRate").removeClass("btn-danger");
		 		$("#controlRate").addClass("btn-info");
		 	}
			return controlValue;
		}
	</script>
  </head>
	
  <body>
    <div class="container">
      <div class="row row-offcanvas row-offcanvas-right">
      	<div class="head col-xs-12 col-sm-7" style="margin-top:10px;">
			<span class="title">自动评价设置</span>
			<span class="desc"> 设置自动评价的频率、以及方式</span>
		</div>
        <div class="formBody col-xs-12 col-sm-8">
		    <form class="form-horizontal" role="form" action="">
			  <div class="form-group">
			  	<label for="inputEmail3" class="col-sm-2 control-label">自动评价</label>
			  	<div class="col-sm-10">
			  	  <div id="controlDiv">
				  	  <label class="control-label closedControl" id="controlStatus">已关闭</label>
					  <button type="button" class="btn btn-info" id="controlRate" value="" onfocus="this.blur()"></button>
				  </div>
				</div>
			  </div>
			  <hr>
			  <div class="form-group">
		      	    <label class="col-sm-2 control-label">订单情况</label>
		      	    <div class="col-sm-10">
		      	    	<div class="radio">
						  <label>
						    <input type="radio" name="trade_rate_condition" id="buyerCondition" value="1" checked>买家已评价
						  </label>
						</div>
					</div>
					<label class="col-sm-2 control-label"></label>
					<div class="col-sm-10">
				        <div class="radio">
						  <label>
						    <input type="radio" name="trade_rate_condition" id="allCondition" value="2">所有交易成功订单
						  </label>
						</div>
					</div>
		      </div>
		      <hr>
			  <div class="form-group">
			  	<label class="col-sm-2 control-label">抢评</label>
			  	<div class="col-sm-10">
				  <label class="radio-inline">
				    <input type="radio" name="grab_switch" id="grabOpen" value="1" >启动
				  </label>
				  <label class="radio-inline">
				    <input type="radio" name="grab_switch" id="grabClosed" value="0" checked>关闭
				  </label>
				</div>
				<label for="inputEmail3" class="col-sm-2 control-label"></label>
				<div class="col-sm-10"  style="margin-top: 10px;color: #FF0000" >
					<span>注意：交易成功订单，如果15天内未有任何一方评价，则该交易无法评价，抢评功能会在交易成功第14天自动为这部分订单评价，建议开启。</span>
				</div>
			  </div>
		      <hr>
			  <div class="form-group">
			  	<label class="col-sm-2 control-label">过滤黑名单</label>
			  	<div class="col-sm-10">
				  <label class="radio-inline">
				    <input type="radio" name="black_list_switch" id="blackOpen" value="1" >启动
				  </label>
				  <label class="radio-inline">
				    <input type="radio" name="black_list_switch" id="blackClosed" value="0" checked>关闭
				  </label>
				</div>
			  </div>
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <button type="button" id="saveConfig" class="btn btn-default">保存</button>
			    </div>
			  </div>
			</form>
        </div><!--/formBody-->
         <div class="help col-xs-12 col-sm-4" style="margin-top:-35px;">
			<div class="panel panel-info">
			  <div class="panel-heading">
			    <h3 class="panel-title">疑问解答</h3>
			  </div>
			  <div class="panel-body">
			  	Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.
			  </div>
			  <!-- List group -->
			  <ul class="list-group">
			    <li class="list-group-item">问题1：获取商品的印象标签有什么条件？</li>
			    <li class="list-group-item">回答1：所有有评价的订单都可以获取商品的印象标签。</li>
			    <li class="list-group-item">Morbi leo risus</li>
			    <li class="list-group-item">Porta ac consectetur ac</li>
			    <li class="list-group-item">Vestibulum at eros</li>
			  </ul>
			</div>
		</div>
      </div><!--/row-->
    </div><!--/.container-->
  </body>
</html>
